<?php
// +----------------------------------------------------------------------
// | WoShiMaiJia Projcet 
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2011 http://woshimaijia.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: xinqiyang <xinqiyang@gmail.com>
// +----------------------------------------------------------------------

/**
 * tag services
 * add /get /destroy tags
 * @author xinqiyang
 *
 */
class TagsService extends BaseService
{
	/**
	 * add id or ids
	 * @param array $array
	 */
	public static function addTags($array)
	{
		return self::adds('tags', $array);
	}
	
	/**
	 * get tags by tagid or ids
	 * @param $tags
	 */
	public static function getTagsById($array)
	{
		if(count($array) && isset($array[0]) && is_array($array[0])){
			return self::gets('tags', 'id in '.strin($array).' and status=0');
		}
		return self::get('tags', $array['id'],'','status=0');
	}
	
	/**
	 * delete tags by array id or id
	 * @param $array mixed string/array
	 */
	public static function tagDestory($array)
	{
		return self::destory('tags',$array);
	}
	
	/**
	 * getwords from the content of 
	 * @param unknown_type $content
	 */
	public static function getWords($content)
	{
		//@TODO:need change the words 
		$cws = scws_new();
		$cws->set_charset('utf8');
		//add dict to the new
		//@TODO:need change the path of the dict，need to change the type,this is async
		$cws->add_dict('/usr/local/scws/etc/words.txt', SCWS_XDICT_TXT);
		$cws->set_duality(true);
		$cws->set_ignore(true);
		$multi = 1;
		$cws->set_multi($multi);
		$cws->send_text($content);
		$r = $cws->get_result();
		$return = array();
		if($r){
			foreach ($r as $one)
			{
				if(strlen($one['word']) >= 4){
					$return[] = $one['word'];
				}
			}
			$return = array_unique($return);
			//do user link
			
		}
		return $return;
	}
	
	
	public static function userAndWords($content)
	{
		
	}
	
}